<template>
  <div>
    <el-dialog
      :title="roomNum"
      v-model="editVisible"
      v-if="editVisible"
      :close-on-click-modal="false"
      @close="handleclose"
      width="80%"
    >
      <el-form>
        <el-form-item label="">
          <el-table
            :data="tableData1"
            @row-click="expandChange"
            :expand-row-keys="expands"
            row-key="id"
            ref="refTable"
          >
            <!--灭弧 devType=16/20  -->
            <!--  在线监测(单相) devType=18/47-->
            <!-- 在线监测(三相) devType=19/51 -->
            <!-- 故障电弧B版 devType=21 -->
            <!-- 故障电弧C版 devType=37 -->
            <el-table-column type="expand">
              <template #default="props">
                <el-form
                  label-position="left"
                  inline
                  class="demo-table-expand"
                  v-if="props.row.dttDevice && props.row.dttDevice.devType"
                >
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 16 ||
                      props.row.dttDevice.devType == 20 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51 ||
                      props.row.dttDevice.devType == 37
                    "
                    label="电压1："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ua',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '电压1'
                        )
                      "
                      >{{ props.row.dttDevice.ua }}V</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 16 ||
                      props.row.dttDevice.devType == 20 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51 ||
                      props.row.dttDevice.devType == 37
                    "
                    label="电流1："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ia',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '电流1'
                        )
                      "
                      >{{ props.row.dttDevice.ia }}A</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 16 ||
                      props.row.dttDevice.devType == 20 ||
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="温度1："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ta',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '温度1'
                        )
                      "
                      >{{ props.row.dttDevice.ta }}℃</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 16 ||
                      props.row.dttDevice.devType == 20 ||
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="温度2："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'tb',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '温度2'
                        )
                      "
                      >{{ props.row.dttDevice.tb }}℃</span
                    >
                  </el-form-item>

                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 21
                    "
                    label="电压："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ua',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '电压'
                        )
                      "
                      >{{ props.row.dttDevice.ua }}V</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 21
                    "
                    label="电流："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ia',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '电流'
                        )
                      "
                      >{{ props.row.dttDevice.ia }}A</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="正向有功："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'e1',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '正向有功'
                        )
                      "
                      >{{ props.row.dttDevice.e1 }}KW/h</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="反向有功："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'e2',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '反向有功'
                        )
                      "
                      >{{ props.row.dttDevice.e2 }}KW/h</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="正向无功："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'e3',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '正向无功'
                        )
                      "
                      >{{ props.row.dttDevice.e3 }}KW/h</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="反向无功："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'e4',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '反向无功'
                        )
                      "
                      >{{ props.row.dttDevice.e4 }}KW/h</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="电压2："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ub',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '电压2'
                        )
                      "
                      >{{ props.row.dttDevice.ub }}V</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="电压3："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'uc',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '电压3'
                        )
                      "
                      >{{ props.row.dttDevice.uc }}V</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="电流2："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ib',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '电流2'
                        )
                      "
                      >{{ props.row.dttDevice.ib }}A</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="电流3："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ic',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '电流3'
                        )
                      "
                      >{{ props.row.dttDevice.ic }}A</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="温度3："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ta',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '温度3'
                        )
                      "
                      >{{ props.row.dttDevice.ta }}℃</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="温度4："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'tb',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '温度4'
                        )
                      "
                      >{{ props.row.dttDevice.tb }}℃</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 21 ||
                      props.row.dttDevice.devType == 37
                    "
                    label="温度L："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ta',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '温度L'
                        )
                      "
                      >{{ props.row.dttDevice.ta }}℃</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 21 ||
                      props.row.dttDevice.devType == 37
                    "
                    label="温度N："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'tb',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '温度N'
                        )
                      "
                      >{{ props.row.dttDevice.tb }}℃</span
                    >
                  </el-form-item>
                  <el-form-item v-show="devType == 37" label="温度L1：">
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'tc',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '温度L1'
                        )
                      "
                      >{{ props.row.dttDevice.tc }}℃</span
                    >
                  </el-form-item>
                  <el-form-item
                    v-show="props.row.dttDevice.devType == 37"
                    label="温度N1："
                  >
                    <span
                      class="pointerc"
                      @click="
                        handletemperature(
                          'tn',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '温度N1'
                        )
                      "
                      >{{ props.row.dttDevice.tn }}℃</span
                    >
                  </el-form-item>
                  <!-- <el-form-item label="温度1：">
                    <span
                      @click="handletemperature"
                      style="color: rgb(28, 97, 187); cursor: pointer"
                      >{{ props.row.id }}</span
                    >
                  </el-form-item> -->

                  <el-form-item
                    v-show="
                      props.row.dttDevice.devType == 16 ||
                      props.row.dttDevice.devType == 20 ||
                      props.row.dttDevice.devType == 18 ||
                      props.row.dttDevice.devType == 47 ||
                      props.row.dttDevice.devType == 19 ||
                      props.row.dttDevice.devType == 51
                    "
                    label="漏电："
                  >
                    <span
                      style="color: red"
                      class="pointerc"
                      @click="
                        handletemperature(
                          'ld',
                          props.row.shunt,
                          props.row.imei,
                          props.row.devType,
                          '漏电'
                        )
                      "
                      >{{ props.row.dttDevice.ld }}mA</span
                    >
                  </el-form-item>
                </el-form>
              </template>
            </el-table-column>
            <el-table-column label="设备号" prop="imei"> </el-table-column>
            <el-table-column label="设备名称" prop="deviceName">
            </el-table-column>
            <el-table-column label="状态" prop="desc">
              <template #default="scope">
                {{ scope.row.isOnline == 0 ? "离线" : "在线" }}
              </template>
            </el-table-column>
            <el-table-column label="开/关" prop="deviceName">
             <template #default="scope">
              <el-switch
                v-model="scope.row.isOnline"
                :active-value="1"
                :inactive-value="0"
                active-color="#13ce66"
                inactive-color="#ff4949"
                @change="handleswitch(scope.row.id,scope.$index)"
              >
              </el-switch>
                  </template>
            </el-table-column>
            <el-table-column label="锁定/解锁" prop="deviceName">
              <template #default="scope">
              <el-switch
                v-model="scope.row.isOnline"
                :active-value="1"
                :inactive-value="0"
                active-color="#13ce66"
                inactive-color="#ff4949"
                @change="handleUnlock(scope.row.id,scope.$index)"
              >
              </el-switch>
                     </template>
            </el-table-column>
            <el-table-column label="使用电量" prop="deviceName">
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { ref, reactive } from "vue";
export default {
  components: {},
  setup(props, context) {
    console.log(context);
    // 参考图片
    const editVisible = ref(context.attrs.editVisible);
    const tableData1 = ref(context.attrs.list);
    console.log(context.attrs);
    const handleclose = () => {
      editVisible.value = false;
      context.emit("handleclose", editVisible.value);
    };
    const handleclick = () => {
      context.emit("handleclick", editVisible.value);
    };
    const handleswitch = (id,index) => {
      context.emit("handleswitch",id,index);
    };
    const handleUnlock = (id,index) => {
      context.emit("handleUnlock",id,index);
    };
    return {
      editVisible,
      tableData1,
      handleclick,
      handleclose,
      handleswitch,
      handleUnlock,
    };
  },
};
</script>
